Release 10.1A: OpenEdge Development:
ProDataSets
COPY-DATASET and COPY-TEMP-TABLE methods
So far this example has shown you how to append additional data to a single ProDataSet, and to control which parts of it get filled in at different times. In this section, you’ll learn about two additional Progress 4GL methods that can assist you when you need to copy or combine data in other ways.
The
COPY-DATASETmethod copies all the data in one ProDataSet to another. For example:
The
source-dataset-handlemust be the handle of an existing static or dynamic ProDataSet. Thetarget-dataset-handlecan be the handle of another static or dynamic ProDataSet with the same temp-table and Data-Relation structure. It can also be a newly created dynamic ProDataSet with only a handle and no structure, that is, the result of executing the statementCREATE DATASETtarget-dataset-handle. If thetarget-datasethas no structure, the table and Data-Relation structure of thesource-datasetis copied to it along with the data. In this case the dynamic target ProDataSet is not given a name, but its temp-tables and their buffers are given the name“cpy_”plus the name of the temp-table or buffer in the source ProDataSet.
COPY-DATASETcopies the temp-tables from source to target in the order that they were defined or added in the two ProDataSets. As soon as it encounters a pair that do not have compatible table definitions, it puts out an error message and terminates the operation. As with other operations, two temp-table definitions are considered compatible if they contain the same number of fields with matching datatypes and extents for each field. Whether the field names are identical in the two tables does not matter. If either the source or target ProDataSet has an extra temp-table or temp-tables at the end of the ProDataSet, theCOPY-DATASETsucceeds because the unpaired tables are ignored.By default, the tables in the target ProDataSet are emptied at the start of the
COPY-DATASEToperation, so that the end result is that the target ProDataSet temp-tables have the same rows as in the source ProDataSet. If you instead want to merge the data in the two ProDataSets, you include the optional secondmerge-flagparameter on the method call. If this logical parameter is present and evaluates to true, then data from the source ProDataSet temp-tables is merged into the target temp-tables according to the rules of the“MERGE”value for a temp-table buffer’sFILL-MODEduring aFILL. That is, rows from the two corresponding tables in each pair are combined so that the target ends up with all the rows that were in either the source or target at the start. If there is a unique index on the target temp-table, all rows from the source that violate that index constraint are silently eliminated during theCOPY-DATASEToperation, so that the target winds up with only one row for each index value. Note that there is no interleaving of data in related tables as it is copied from the source ProDataSet to the target. Each temp-table is copied individually in its entirety, starting at the top of the ProDataSet hierarchy. If duplicate rows are eliminated from a parent table in the course of the copy, this has no effect on the related rows in any child table.If the source ProDataSet has any before-tables that have any rows in them, you cannot use
COPY-DATASETon that ProDataSet. It would not be appropriate to copy and duplicate this transactional data, which is presumably waiting to be committed back to its Data-Source. Since it would also not be appropriate to copy the ProDataSet and silently omit this data, it’s simply not allowed. If you need to copy after-tables from one ProDataSet to another at a time when the before-tables have data in them, you can use theCOPY-TEMP-TABLEmethod.
COPY-DATASEThas four additional positional, optional arguments. Thereplace-mode,loose-copy-modeandcurrent-onlyoptions areLOGICALdatatypes, and thepairs-listoption is a character expression. The full syntax ofCOPY-DATASETis. For example:
The
COPY-TEMP-TABLEmethod works similarly for individual temp-tables, as shown:
You can use the
COPY-TEMP-TABLEmethod on any source or target temp-table, whether it is part of a ProDataSet or not. Therefore you can use this method to copy individual temp-tables from one ProDataSet to another, or for other temp-tables having nothing to do with ProDataSets.As with
COPY-DATASET, by default the target temp-table is emptied at the start of the operation. The rules for temp-table compatibility, the use of the optional merge-flag, and so on, are the same as forCOPY-DATASET.The replace-mode argument
The
replace-modeoption defaults toFALSE. Ifreplace-modeisTRUE, Progress tries to find the corresponding row in the target table, through the target’s unique primary index. If a corresponding row is not found in the target table, Progress uses the source row to create a new target row. If Progress finds the row in the target, it copies the source row values into that row. If the target row has aBEFORE-TABLErow, that row is left in place. There must be a unique primary index on each target member table in order for thereplace-modeoption to be used.When
replace-modeisTRUE, it does not matter ifappend-modeisTRUEorFALSE. The target table is not emptied prior to the copy operation.The loose-copy-mode argument
By default, pairs of source and target temp-tables being copied by the
COPY-DATASETorCOPY-TEMP-TABLEmethod must have compatible definitions. Theloose-copy-modeoption overrides this default.For the
COPY-DATASETmethod, ifloose-copy-modeisTRUE, the parameter applies to each temp-table buffer in the ProDataSet. Thus, the remainder of this paragraph applies to both theCOPY-DATASETandCOPY-TEMP-TABLEmethods. Ifloose-copy-modeisTRUEfor a temp-table buffer, Progress effectively performs aBUFFER-COPYfrom source to target.BUFFER-COPYis more flexible than the default behavior ofCOPY-TEMP-TABLEorCOPY-DATASETbecause it matches each source field to its corresponding field in the target by name, and ignores fields that do not match, without error. This is somewhat more expensive than the default behavior ofCOPY-DATASETandCOPY-TEMP-TABLE, which assumes compatible definitions field-for-field between source and target. Whenloose-copy-modeisTRUE, Progress checks for an existing field-mapping between the two buffers specified in a previousATTACH-DATA-SOURCEoperation. If the source temp-table is in fact the Data-Source for the target, then its field-mapping is used to match up field pairs with differing names, just as forBUFFER-COPY. If there is noATTACH-DATA-SOURCEbetween the two buffers, the copy is done by matching field names and only copying those fields that appear in both source and target. As withBUFFER-COPY, different field order and missing fields do not prevent the method from succeeding. There is also no requirement that indexes on the two temp-tables be identical.The pairs-list argument
The
pairs-listargument only applies toCOPY-DATASET. Thepairs-listis a comma-separated list of target and source tables to be copied, such as:targetT1,sourceT1,targetT2,sourceT2. If thepairs-listis present, the copy is done between only those member tables given in thepairs-list, by matching target and source table names. If thepairs-listis not given, the tables are copied in the order in which they were defined or added in the two ProDataSets.If one ProDataSet has more tables than the other, the extra unpaired tables are ignored. In other words, you can use
COPY-DATASETwithout thepairs-listoption to copy one ProDataSet to another, even when one ProDataSet has more tables than the other, as long as the tables to be copied have the same relative positions within the ProDataSet structure. This is the same as the order in which the tables would be returned by theGET-BUFFER-HANDLE (i)method.If the tables to be copied are not in the same relative order, then you must specify the
pairs-listoption to tell Progress which source tables go with which targets. If the source and target tables don’t match up in their relative order within their respective ProDataSets, you must specify thepairs-listeven if the table names are the same.For example, given a source ProDataSet with temp-tables
T1,T2, andT3, and a target ProDataSet with just tablesT1andT3, you must define thepairs-listoption to beT1,T1,T3,T3, because the relative position ofT3in the two ProDataSets is not the same, even though the table names are the same. It is also worth noting that for static temp-table definitions, it is not possible for the source and target temp-tables to have the same name anyway, since each static name defines a single unique instance with that name.The current-only argument
The
current-onlyargument also applies only toCOPY-DATASET. Ifcurrent-onlyis present and isTRUE, it tells Progress to copy only the current buffer contents of each source ProDataSet buffer to the target ProDataSet. This option can be useful in situations where the business logic needs to deal with a modified row and its parent (and possibly grand-parent, etc.) without using any other rows. Thecurrent-onlyoption is a way of getting this minimal set of data to pass to such an operation. Note that you might need to set theAUTO-SYNCHRONIZEattribute toTRUEor execute theSYNCHRONIZE( )method to ensure that the contents of each buffer are what is needed. Since the usefulness of thecurrent-onlyoption is that it automatically copies a single row at multiple levels at once, it is supported only forCOPY-DATASET. For a temp-table, you can use a singleBUFFER-COPYstatement or method to copy a single row.
|
Copyright © 2005 Progress Software Corporation www.progress.com Voice: (781) 280-4000 Fax: (781) 280-4095 |